#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <set>
#include "BloomFilter.h"
#include "BloomFilterHashFunctions.h"
#include "MurmurHash.h"


int main( int argc, const char * argv[ ] )
{
	const unsigned int R = 100000000;
	const unsigned int N = 10000;

	std::set< unsigned int > s;
	for( unsigned int i = 0; i < N; ++i )
	{
		unsigned int e = rand( ) % R;
		s.insert( e );
	}

//	const unsigned int NumBits = N * 46 / 10 + 1;
//	const unsigned int NumFunctions = (NumBits * 6) / (N * 10) + 1;

	const unsigned int NumBits = N * 4;
	const unsigned int NumFunctions = 3;

	const unsigned int S1 = NumBits / 8;
	unsigned int S2 = s.size( ) * sizeof( unsigned int );

	KeyValueFile::BloomFilterStatic< NumBits, NumFunctions > bf;
	KeyValueFile::BloomFilterHashFunctions< KeyValueFile::BloomFilterMurmurHashPOD< unsigned int >, NumBits, NumFunctions > HF;

	for( std::set< unsigned int >::iterator end = s.end( ),
		 it = s.begin( ); it != end; ++it )
	{
		bf.Insert( HF, (*it) );
	}

	const unsigned int T = 100000;

	unsigned int numFalsePositive = 0;
	for( unsigned int i = 0; i < T; ++i )
	{
		unsigned int e = rand( ) % R;
		bool t1 = bf.Find( HF, e );
		bool t2 = s.find( e ) != s.end( );

		if( t1 &&
			!t2 )
		{
			numFalsePositive += 1;
		}

		if( !t1 &&
			t2 )
		{
			int dummy = 0;
		}
	}


/*	const char * s = "DEADSORBIMENTO";
	unsigned int h = murmurHash( s, strlen( s ) );
*/

	return 0;
}